package com.brainhealth.customer.handle;

import com.brainhealth.common.enums.PayStatus;
import com.brainhealth.customer.domain.ExerciseOrder;
import com.brainhealth.customer.domain.ScoreMallOrder;
import com.brainhealth.customer.mapper.ExerciseOrderMapper;
import com.brainhealth.customer.service.IScoreMallOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author wolong
 * @description:
 */
@Component
public class RedissionService
{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ExerciseOrderMapper exerciseOrderMapper;

    @Autowired
    private IScoreMallOrderService scoreMallOrderService;

    public void handleWLClueAdd(String msg)
    {
        ExerciseOrder exerciseOrder = exerciseOrderMapper.selectExerciseOrderByOrderId(msg);
        if (exerciseOrder.getStatus() == PayStatus.Unpaid)
        {
            exerciseOrder.setStatus(PayStatus.Cancel);
            exerciseOrder.setUpdateTime(new Date());
            int result = exerciseOrderMapper.updateExerciseOrder(exerciseOrder);
            if (result > 0)
            {
                logger.info("超时订单取消成功！");
            }else
            {
                logger.error("取消订单失败！");
            }
        }
    }

    public void handleScoreOrderClueAdd(String orderId)
    {
        ScoreMallOrder scoreMallOrder = scoreMallOrderService.selectScoreMallOrderByOrderId(orderId);
        if (scoreMallOrder.getStatus() == PayStatus.Unpaid)
        {
            scoreMallOrder.setStatus(PayStatus.Cancel);
            scoreMallOrder.setUpdateTime(new Date());
            int result = scoreMallOrderService.updateScoreMallOrder(scoreMallOrder);
            if (result > 0)
            {
                logger.info("超时订单取消成功！");
            }else
            {
                logger.error("取消订单失败！");
            }
        }
    }
}
